package org.jeecg.modules.demo.ipds.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.jeecg.modules.demo.ipds.entity.vo.SpecKeyValueDO;
import org.jeecg.modules.demo.ipds.entity.vo.TreeByteListVo;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * @Description: 字节列表
 * @Author: jeecg-boot
 * @Date:   2024-01-31
 * @Version: V1.0
 */
@Data
@TableName(value = "tree_byte_list", autoResultMap = true)
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="tree_byte_list对象", description="字节列表")
@NoArgsConstructor
@AllArgsConstructor
@XmlRootElement(name = "ByteItem")
@XmlAccessorType(XmlAccessType.FIELD)
public class TreeByteList implements Serializable {
    private static final long serialVersionUID = 1L;

	/**主键*/
	@TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "主键")
    private java.lang.String id;
	/**创建人*/
    @ApiModelProperty(value = "创建人")
    private java.lang.String createBy;
	/**创建日期*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建日期")
    private java.util.Date createTime;
	/**更新人*/
    @ApiModelProperty(value = "更新人")
    private java.lang.String updateBy;
	/**更新日期*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新日期")
    private java.util.Date updateTime;
	/**所属部门*/
    @ApiModelProperty(value = "所属部门")
    private java.lang.String sysOrgCode;
	/**序号*/
	@Excel(name = "序号", width = 15)
    @ApiModelProperty(value = "序号")
    private java.lang.String sn;
	/**字节名称*/
	@Excel(name = "字节名称", width = 15)
    @ApiModelProperty(value = "字节名称")
    @JsonProperty("name")
    private java.lang.String byteName;


    /**数据类型*/
	@Excel(name = "数据类型", width = 15)
    @ApiModelProperty(value = "数据类型")
    private java.lang.String dataType;
	/**数据范围*/
	@Excel(name = "数据范围", width = 15)
    @ApiModelProperty(value = "数据范围")
    private java.lang.String valueScope;
	/**分辨率*/
	@Excel(name = "分辨率", width = 15)
    @ApiModelProperty(value = "分辨率")
    private java.lang.String resolutionRatio;

    @ApiModelProperty(value = "分辨率最大长度")
    private  Integer resolutionRatioLength;

	/**有无符号*/
	@Excel(name = "有无符号", width = 15)
    private transient java.lang.String isSymbolString;

    private byte[] isSymbol;

    public TreeByteList(ByteListReuse treeByteList, String ipTreeId, List<BitList> bitList, List<List<TreeByteList2>> children) {

            this.byteName=treeByteList.getByteName();
            this.annotation=treeByteList.getAnnotation();
            this.dataType=treeByteList.getDataType();
            this.reuseField= treeByteList.getReuseField();
            this.defaultValue=treeByteList.getDefaultValue();
            this.extendField=treeByteList.getExtendField();
            this.fieldLength=treeByteList.getFieldLength();
            this.fieldType=treeByteList.getFieldType();
            this.fieldTypeValue=treeByteList.getFieldTypeValue();
            this.indexSx=treeByteList.getIndexSx();

            this.resolutionRatio=treeByteList.getResolutionRatio();
            this.sn=treeByteList.getSn();
            this.unit=treeByteList.getUnit();
            this.valueScope=treeByteList.getValueScope();
            this.resolutionRatioLength = treeByteList.getResolutionRatioLength();

            this.isSymbolString = treeByteList.getIsSymbolString();

            this.ipTreeId = ipTreeId;
            this.bitLists = bitList;
            this.children =children;


    }

    public TreeByteList(TreeByteListVo treeByteList,List<SpecKeyValueDO> specKeyValueDOS) {
        this.byteName=treeByteList.getByteName();
        this.annotation=treeByteList.getAnnotation();
        this.dataType=treeByteList.getDataType();
        this.defaultValue=treeByteList.getDefaultValue();
        this.fieldLength=treeByteList.getFieldLength();
        this.fieldType=treeByteList.getFieldType();
        this.fieldTypeValue=treeByteList.getFieldTypeValue();
        this.resolutionRatio=treeByteList.getResolutionRatio();
        this.sn=treeByteList.getSn();
        this.unit=treeByteList.getUnit();
        this.valueScope=treeByteList.getValueScope();
        this.resolutionRatioLength = treeByteList.getResolutionRatioLength();
        this.isSymbolString = treeByteList.getIsSymbolString();
        this.ipTreeId = treeByteList.getIpTreeId();
        this.extendField=specKeyValueDOS;
    }

    public byte[] getIsSymbol(){
        if(isSymbolString==null){
            return null;
        }
        try {
            return isSymbolString.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public String getIsSymbolString(){
        if(isSymbol==null || isSymbol.length==0){
            return "";
        }
        try {
            return new String(isSymbol,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return "";
    }
	/**字段类型*/
	@Excel(name = "字段类型", width = 15)
    @ApiModelProperty(value = "字段类型")
    private java.lang.String fieldType;
	/**字段类型值*/
	@Excel(name = "字段类型值", width = 15)
    @ApiModelProperty(value = "字段类型值")
    private java.lang.String fieldTypeValue;
	/**默认值*/
	@Excel(name = "默认值", width = 15)
    @ApiModelProperty(value = "默认值")
    private java.lang.String defaultValue;
	/**单位*/
	@Excel(name = "单位", width = 15)
    @ApiModelProperty(value = "单位")
    private java.lang.String unit;
	/**复用字段*/
	@Excel(name = "是否帧头", width = 15)
    private  java.lang.String reuseField;

	/**字段长度*/
	@Excel(name = "字段长度", width = 15)
    @ApiModelProperty(value = "字段长度")
    @JsonProperty("length")
    private java.lang.String fieldLength;
	/**注释*/
	@Excel(name = "注释", width = 15)
    @ApiModelProperty(value = "注释")
    private java.lang.String annotation;
	/**扩展字段*/

//    private String extendField;
	@Excel(name = "扩展字段", width = 15)
    @ApiModelProperty(value = "扩展字段")
    @TableField(typeHandler = JacksonTypeHandler.class)
    List<SpecKeyValueDO> extendField;

    @TableField(exist = false)
    @ApiModelProperty(value = "位集合")
    List<BitList> bitLists;

    @TableField(exist = false)
    @ApiModelProperty(value = "子帧集合")
    private List<List<TreeByteList2>> children;



    @ApiModelProperty(value = "表类型")
    private  String tableType;
	/**协议树ID*/
	@Excel(name = "协议树ID", width = 15)
    @ApiModelProperty(value = "协议树ID")
    private java.lang.String ipTreeId;

    @ApiModelProperty(value = "顺序")
    private Integer indexSx;

    @ApiModelProperty(value = "十六进制数")
    private String hexNum;

    @TableField(exist = false)
    @ApiModelProperty(value = "sn")
    private String index;
}
